package com.jdj.framework.dao.mybatis.service.impl;

import com.jdj.framework.core.base.utils.BeanUtils;
import com.jdj.framework.core.base.vo.BaseVo;
import com.jdj.framework.core.base.vo.PageInfo;
import com.jdj.framework.dao.mybatis.dao.MyBatisDao;
import com.jdj.framework.dao.mybatis.entity.BaseEntity;
import com.jdj.framework.dao.mybatis.entity.condition.BaseEntityCondition;
import com.jdj.framework.dao.mybatis.service.BaseService;
import java.io.Serializable;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

/**
 * BaseService的实现类
 * @author caijinbang
 * @date 2019-04-14 13:35
 */
public abstract class BaseServiceImpl implements BaseService {
    protected final Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * spring context 配置id为myBatisDao的默认注入
     */
    @Autowired(required = false)
    @Qualifier(value = "myBatisDao")
    private MyBatisDao myBatisDao;

    @Override
    public <Condition extends BaseEntityCondition> int countByCondition(Condition condition) {
        return getMyBatisDao().countByCondition(condition);
    }

    @Override
    public <Entity extends BaseEntity, Condition extends BaseEntityCondition> List<Entity> selectByCondition(
        Condition condition) {
        return getMyBatisDao().selectByCondition(condition);
    }

    @Override
    public <Entity extends BaseEntity, Condition extends BaseEntityCondition> Entity selectOneByCondition(
        Condition condition) {
        return getMyBatisDao().selectOneByCondition(condition);
    }

    @Override
    public <Condition extends BaseEntityCondition> PageInfo selectPageByCondition(Condition condition) {
        return getMyBatisDao().selectPageByCondition(condition);
    }

    @Override
    public <Entity extends BaseEntity> Entity selectByPrimaryKey(Class<Entity> entityClass, Serializable primaryKeyValue) {
        return getMyBatisDao().selectByPrimaryKey(entityClass, primaryKeyValue);
    }

    @Override
    public <Entity extends BaseEntity> Entity selectByPrimaryKey(Entity entity) {
        return getMyBatisDao().selectByPrimaryKey(entity);
    }

    @Override
    public <Entity extends BaseEntity> int deleteByPrimaryKey(Class<Entity> entityClass, Serializable primaryKeyValue) {
        return getMyBatisDao().deleteByPrimaryKey(entityClass, primaryKeyValue);
    }

    @Override
    public <Entity extends BaseEntity> int insert(Entity entity) {
        return getMyBatisDao().insert(entity);
    }

    @Override
    @Deprecated
    public <Entity extends BaseEntity> int insert(List<Entity> entities) {
        return getMyBatisDao().insert(entities);
    }

    @Override
    public <Entity extends BaseEntity> int insertList(List<Entity> entities) {
        return getMyBatisDao().insertList(entities);
    }

    @Override
    public <Entity extends BaseEntity, T> T insertWithPrimaryKey(Entity entity) {
        return getMyBatisDao().insertWithPrimaryKey(entity);
    }

    @Override
    public <Entity extends BaseEntity> List<Serializable> insertWithPrimaryKeys(List<Entity> entities) {
        return getMyBatisDao().insertWithPrimaryKeys(entities);
    }

    @Override
    public <Entity extends BaseEntity> List<Serializable> insertListWithPrimaryKeys(List<Entity> entities) {
        return getMyBatisDao().insertListWithPrimaryKeys(entities);
    }

    @Override
    public <Entity extends BaseEntity> Entity insertWithQuery(Entity entity) {
        return getMyBatisDao().insertWithQuery(entity);
    }

    @Override
    public <Entity extends BaseEntity> List<Entity> insertWithQuery(List<Entity> entities) {
        return getMyBatisDao().insertWithQuery(entities);
    }

    @Override
    public <Entity extends BaseEntity> int delete(Entity entity) {
        return getMyBatisDao().delete(entity);
    }

    @Override
    public int deleteByCondition(BaseEntityCondition condition) {
        return getMyBatisDao().deleteByCondition(condition);
    }

    @Override
    public <Entity extends BaseEntity> int delete(List<Entity> entities) {
        return getMyBatisDao().delete(entities);
    }

    @Override
    public <Entity extends BaseEntity> int update(Entity entity) {
        return getMyBatisDao().update(entity);
    }

    @Override
    public <Entity extends BaseEntity> int updateNotEmpty(Entity entity) {
        return getMyBatisDao().updateNotEmpty(entity);
    }

    @Override
    public <Entity extends BaseEntity> int updateNotNull(Entity entity) {
        return getMyBatisDao().updateNotNull(entity);
    }

    @Override
    public <Entity extends BaseEntity, Condition extends BaseEntityCondition> int updateByCondition(Entity entity,
        Condition condition) {
        return getMyBatisDao().updateByCondition(entity, condition);
    }

    @Override
    public <Entity extends BaseEntity> int update(List<Entity> entities) {
        return getMyBatisDao().update(entities);
    }

    @Override
    public <Entity extends BaseEntity> int updateNotEmpty(List<Entity> entities) {
        return getMyBatisDao().updateNotEmpty(entities);
    }

    @Override
    public <Entity extends BaseEntity> int updateNotNull(List<Entity> entities) {
        return getMyBatisDao().updateNotNull(entities);
    }

    @Override
    public <Entity extends BaseEntity, T> T updateWithPrimaryKey(Entity entity) {
        return getMyBatisDao().updateWithPrimaryKey(entity);
    }

    @Override
    public <Entity extends BaseEntity, T> T updateNotEmptyWithPrimaryKey(Entity entity) {
        return getMyBatisDao().updateNotEmptyWithPrimaryKey(entity);
    }

    @Override
    public <Entity extends BaseEntity, T> T updateNotNullWithPrimaryKey(Entity entity) {
        return getMyBatisDao().updateNotNullWithPrimaryKey(entity);
    }

    @Override
    public <Entity extends BaseEntity> List<Serializable> updateWithPrimaryKeys(List<Entity> entities) {
        return getMyBatisDao().updateWithPrimaryKeys(entities);
    }

    @Override
    public <Entity extends BaseEntity> List<Serializable> updateNotEmptyWithPrimaryKeys(List<Entity> entities) {
        return getMyBatisDao().updateNotEmptyWithPrimaryKeys(entities);
    }

    @Override
    public <Entity extends BaseEntity> List<Serializable> updateNotNullWithPrimaryKeys(List<Entity> entities) {
        return getMyBatisDao().updateNotNullWithPrimaryKeys(entities);
    }

    @Override
    public <Entity extends BaseEntity> Entity updateWithQuery(Entity entity) {
        return getMyBatisDao().updateWithQuery(entity);
    }

    @Override
    public <Entity extends BaseEntity> Entity updateNotEmptyWithQuery(Entity entity) {
        return getMyBatisDao().updateNotEmptyWithQuery(entity);
    }

    @Override
    public <Entity extends BaseEntity> Entity updateNotNullWithQuery(Entity entity) {
        return getMyBatisDao().updateNotNullWithQuery(entity);
    }

    @Override
    public <Entity extends BaseEntity> List<Entity> updateWithQuery(List<Entity> entities) {
        return getMyBatisDao().updateWithQuery(entities);
    }

    @Override
    public <Entity extends BaseEntity> List<Entity> updateNotEmptyWithQuery(List<Entity> entities) {
        return getMyBatisDao().updateNotEmptyWithQuery(entities);
    }

    @Override
    public <Entity extends BaseEntity> List<Entity> updateNotNullWithQuery(List<Entity> entities) {
        return getMyBatisDao().updateNotNullWithQuery(entities);
    }

    @Override
    public <Entity extends BaseEntity> int save(Entity entity) {
        return getMyBatisDao().save(entity);
    }

    @Override
    public <Entity extends BaseEntity> int save(List<Entity> entities) {
        return getMyBatisDao().save(entities);
    }

    @Override
    public <Entity extends BaseEntity> Entity saveWithQuery(Entity entity) {
        return getMyBatisDao().saveWithQuery(entity);
    }

    @Override
    public <Entity extends BaseEntity> List<Entity> saveWithQuery(List<Entity> entities) {
        return getMyBatisDao().saveWithQuery(entities);
    }

    @Override
    public <Entity extends BaseEntity, VO extends BaseVo> Entity toEntity(Class<Entity> clazz, VO vo) {
        return BeanUtils.copyToNewBean(vo, clazz);
    }

    @Override
    public <Entity extends BaseEntity, VO extends BaseVo> List<Entity> toEntities(Class<Entity> clazz, List<VO> vos) {
        return BeanUtils.copyToNewList(vos, clazz);
    }

    @Override
    public <Entity extends BaseEntity, VO extends BaseVo> VO toVO(Class<VO> clazz, Entity entity) {
        return BeanUtils.copyToNewBean(entity, clazz);
    }

    @Override
    public <Entity extends BaseEntity, VO extends BaseVo> List<VO> toVOs(Class<VO> clazz, List<Entity> entities) {
        return BeanUtils.copyToNewList(entities, clazz);
    }

    @Override
    public MyBatisDao getMyBatisDao() {
        return this.myBatisDao;
    }

    @Override
    public MyBatisDao getDao() {
        return this.myBatisDao;
    }
}
